﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Web.Configuration;


public class utenteCore
{
	public utenteCore()
	{

	}

    private String _username;

    public String username
    {
        get { return _username; }
        set 
        { 
            _username = value;
            settaTutto();
        }
    }
    

    private String _name;

    public String name
    {
        get { return _name; }
        set { _name = value; }
    }

    private String _surname;

    public String surname
    {
        get { return _surname; }
        set { _surname = value; }
    }

    private String _email;

    public String email
    {
        get { return _email; }
        set { _email = value; }
    }

    private String _img;

    public String img
    {
        get { return _img; }
        set 
        { 
            _img = value;
            updateImgDb();
        }
    }


    static public List<String> AllIdMessage(String s)
    {
            return DB.selectQuery("ForumDB", "select id_message from message where sender='" + s + "' or receiver='" + s + "'");   
    }
    static public List<String> AllIdMessageSend(String s)
    {
            return DB.selectQuery("ForumDB", "select id_message from message where sender='" + s + "'");
    }
    static public List<String> AllIdMessageRec(String s)
    {
        return DB.selectQuery("ForumDB", "select id_message from message where receiver='" + s + "'");
    }
    public static List<String> AllTextMessage(String s)
    {
        return DB.selectQuery("ForumDB", "select text from message where id_message='" + s + "'");
    }
    public static List<String> AllTitleMessage(String s)
    {
        return DB.selectQuery("ForumDB", "select title from message where id_message='"+s+"'");
    }
    public static List<String> AllSenderMessage(String s)
    {
        return DB.selectQuery("ForumDB", "select sender from message where id_message='" + s + "'");
    }
    public static List<String> AllReceiverMessage(String s)
    {
        return DB.selectQuery("ForumDB", "select receiver from message where id_message='" + s + "'");
    }

    private void settaTutto() { 
    
        this.name = DB.selectQuery("ForumDB", "SELECT [name] FROM [ForumDB].[dbo].[UserForum] where [username] = '" + this.username + "'")[0];
        this.surname = DB.selectQuery("ForumDB", "SELECT [surname] FROM [ForumDB].[dbo].[UserForum] where [username] = '" + this.username + "'")[0];
        this.email= DB.selectQuery("ForumDB", "SELECT [email] FROM [ForumDB].[dbo].[UserForum] where [username] = '" + this.username + "'")[0];
        this.img = DB.selectQuery("ForumDB", "SELECT [avatar] FROM [ForumDB].[dbo].[UserForum] where [username] = '" + this.username + "'")[0];
  
    }

    private void updateImgDb() {
        DB.insertWithOutPar("ForumDB", "update UserForum set avatar ='"+this.img+"' where username = '"+ this.username + "'");
    }
    public void update()
    {
        DB.insertWithOutPar("ForumDB", "update UserForum set name ='" + this.name + "', surname='"+this.surname +"', email='"+this.email+"' where username = '" + this.username + "'");
     
    }
    public void newPwd(String s) {
        DB.insertWithOutPar("ForumDB", "update UserForum set password ='" + s + "' where username = '" + this.username + "'");
   
    }
    public static String imgUsr(String s){
    
        return DB.selectQuery("ForumDB", "SELECT [avatar] FROM [ForumDB].[dbo].[UserForum] where [username] = '" + s + "'")[0];
    }
    


}